package com.jaws.core.mvc.exception;
import com.jaws.core.common.vo.OpResponse;

/**
 * API 前置的异常码划分为:
 * @author maojian
 * 
 * <li>公共模块: 100,公共模块错误码: 100000~100999</li>
 * @date 2017-05-10 17:53:03
 * @since v1.0.0
 */
public enum JawsMvcExceptionCode implements IErrors<OpResponse>{
    TOKEN_CHECK_ERROR(1000001 , "TOKEN校验错误"),
    PARAM_ERROR(1000002 , "参数校验不合法%s"),
    SIGN_AUTHENTICATION_ERROR(1000003 , "接口签名不正确"),
    ACCESS_REFUSED(1000004 , "请求拒绝");




    private int code;
    private String desc;
    private JawsMvcExceptionCode(int code,String desc){
        this.code = code;
        this.desc = desc;
    }
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
    
    public OpResponse parse() {
    	OpResponse result = new OpResponse();
        result.setCode(code);
        result.setDisplay(desc);
        return result;
    }

    @Override
    public OpResponse parse(Object... args) {
    	OpResponse result = new OpResponse();
        result.setCode(code);
        String formatReason = String.format(desc, args);
        result.setDisplay(formatReason);
        return result;
    }

    @Override
    public OpResponse parseMsg(String message, Object... args) {
        this.desc = message;
        return parse(args);
    }
    
    @Override
    public JawsMvcException exp() {
        return new JawsMvcException(code, desc);
    }

    @Override
    public JawsMvcException exp(Object... args) {
        String formatReason = String.format(desc, args);
        return new JawsMvcException(code, formatReason);
    }

    @Override
    public JawsMvcException expMsg(String message, Object... args) {
        String formatReason = String.format(message, args);
        return new JawsMvcException(code, formatReason);
    }
    @Override
    public JawsMvcException exp(Throwable arg0, Object... arg1) {
        return null;
    }
    @Override
    public JawsMvcException expMsg(String arg0, Throwable arg1, Object... arg2) {
        return null;
    }
    
    
}
